package com.lin.reggie.mapper;

import com.lin.reggie.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ShoppingCartMapper {

    //将菜品或套餐存入购物车
    //查看购物车里面 菜品id 或者 套餐id 的数据
    ShoppingCart findByShoppingCart(ShoppingCart shoppingCart);

    //更新指定购物车的数据数量 根据购物车（id主键）更新数量
    @Update("update shopping_cart set number=#{number} where id=#{id}")
    Integer updateNumber(@Param("id") Long id, @Param("number") Integer number);

    //插入一条数据
    @Insert("insert into shopping_cart values(null,#{name},#{image},#{userId},#{dishId},#{setmealId}," +
            "#{dishFlavor},#{number},#{amount},#{createTime})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    Integer save(ShoppingCart shoppingCart);


    //查询购物车
    @Select("select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart>findCartByUserId(@Param("userId") Long userId);

    //清空购物车
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void clean(Long userId);

    //删除菜品或套餐
    void deleteShoppingCart(Long id);
}
